<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
  <meta name="referrer" content="no-referrer"/>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>博客管理登录</title>
  <link href="../static/images/favicon.ico" th:href="@{/images/favicon.ico}" rel="icon" type="image/x-ico">
  <link rel="stylesheet" href="../../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}"  />
  <link rel="stylesheet" href="../../static/css/me.css" th:href="@{/css/me.css}">
  <link rel="stylesheet" href="../../static/css/element-ui-index.css" th:href="@{/css/element-ui-index.css}">

</head>
<body class="admin-body">

<div id="app" class="container text-center">
    <div class="w-100 me-auto ms-auto" style="max-width: 400px;margin-top: 20vh">
        <h1 class="h3 mb-3 fw-normal">博客后台</h1>

        <div class="form-floating mb-3">
            <input id="usernameInput" type="text" class="form-control" v-model="form.username" >
            <label>账号</label>
        </div>
        <div class="form-floating mb-3">
            <input id="passwordInput" type="password" class="form-control" v-model="form.password">
            <label>密码</label>
        </div>

        <button class="w-100 btn btn-lg btn-primary" type="submit" @click="login" >登陆</button>
    </div>
</div>

</body>

<!-- import Vue before Element -->
<script src="../../static/lib/vue.js"                   th:src="@{/lib/vue.js}"></script>
<!-- import JavaScript -->
<script src="../../static/lib/element-ui-index.js"      th:src="@{/lib/element-ui-index.js}"></script>
<script src="../../static/lib/axios.min.js"             th:src="@{/lib/axios.min.js}"></script>
<script src="../../static/lib/axiosInstance.js"         th:src="@{/lib/axiosInstance.js}"></script>

<script>
    new Vue({
        el: '#app',
        data: function () {
            return {
                form:{
                    username:'',
                    password:'',
                },
                rememberMe:false
            }
        },
        methods:{
            login(){
                // 保存记住我
                axiosInstance.post('/admin/login',this.form).then(res=>{
                    if (res.code === 20000){
                        window.location.href = '/admin/dashboard';
                    }
                })
            }
        },
        mounted() {
            document.getElementById("usernameInput").addEventListener("keypress", event => {
                if (event.key === "Enter") {
                    this.login();
                }
            });

            document.getElementById("passwordInput").addEventListener("keypress", event => {
                if (event.key === "Enter") {
                    this.login();
                }
            })
        }
    })
</script>

</html>
